<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>连锁门店管理</title>
	<link rel="stylesheet" type="text/css" href="../../rs/plugins/easyui/themes/metro/easyui.css">
	<link rel="stylesheet" type="text/css" href="../../rs/plugins/easyui/themes/icon.css">
	<link href="../../rs/css/bootstrap.min14ed.css" rel="stylesheet">
	<link href="../../rs/css/style.min862f.css" rel="stylesheet">
	<script type="text/javascript" src="../../rs/plugins/easyui/jquery.min.js"></script>
	<script type="text/javascript" src="../../rs/plugins/easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="../../rs/plugins/easyui/locale/easyui-lang-zh_CN.js"></script>
	<script src="../../rs/js/jquery.cookie.js"></script>
	<script src="../../rs/js/common_qj.js"></script>
	<style>
		html,body{ margin:0px; height:100%;}
	</style>
</head>
<body >
<table id="table" class="easyui-datagrid"  style="width:100%;height:100%;padding: 10px;"
			data-options="
			rownumbers:true,
			singleSelect:'false',
			method:'get' ,
			toolbar:'#easyui_toolbar',
			fit:true,
			fitColumns:true,
	        fit:'true'">
		<thead>
			<tr>

				<th data-options="field:'cobh',align:'left',formatter:formatId,width:20" >企业编号</th>
				<th data-options="field:'shbh',align:'left',width:20" >店铺编号</th>
				<th data-options="field:'jmg',align:'left',width:30">加密狗</th>
				<th data-options="field:'bz',align:'left',width:30">提示</th>
				<th data-options="field:'yz',align:'left',width:30">备注</th>
				<th data-options="field:'op_rq',align:'left',width:30">操作日期</th>
				<th data-options="field:'sfzt',align:'center',width:10,formatter:formatzt">状态</th>
			</tr>
		</thead>
	</table>

	<div id="easyui_toolbar" region="north" border="false"
	  style="height: 45px;padding: 2px 5px; ">
		<div style="float: left;width:350px">
			<div class="input-group ">
				<span class="input-group-btn">
					<button style="margin-right: -2px;height:34px;background-color: #FFF;border: 1px solid #e5e6e7;font-size: 14px" type="button" class="btn btn-sm ">企业编号</button>
				</span>
				<select class="form-control" id="cobh">
					<option value="all">所有企业</option>
				</select>

			</div>
		</div>




		<div id="tb" class="input-group" style="float: right; margin-right: 10px;width:350px">
			<input type="text" class="form-control" id="searchtext" placeholder="输入搜索关键字" value="">
			<div class="input-group-btn">
				<button type="button" class="btn btn-white dropdown-toggle" onclick="do_search()" style="border-radius: 0px;">
					搜索
				</button>

			</div>
		</div>
	</div>


<div style="display: none" id="open_edit">
	<form id="edit_from">
		<div class="input-group" style="display:none">
			<div class="input-group-btn">
				<button type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown"> 企业编号</button>
			</div>
			<input type="text" class="form-control"   name="rid"    required="true"  >
		</div>
		<div class="input-group" style="display:none">
			<div class="input-group-btn">
				<button type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown"> 企业编号</button>
			</div>
			<input type="text" class="form-control"   name="cobh"    required="true"  >
		</div>
		<div class="input-group" style="padding: 20px 20px 10px 20px;">
			<div class="input-group-btn">
				<button type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown">加密狗&nbsp;&nbsp;&nbsp;&nbsp;</button>
			</div>
			<input type="text" class="form-control "   name="jmg"    required="true"  >
		</div>

		<div class="input-group" style="padding: 0px 20px 10px 20px;">
			<div class="input-group-btn">
				<button style="margin-right:-2px;height:34px" type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown">提&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;示</button>
			</div>
			<input type="text" class="form-control " name="bz">
		</div>
		<div class="input-group" style="padding: 0px 20px 8px 20px;">
			<div class="input-group-btn">
				<button style="margin-right: -2px;height: 34px;" type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown"> 状&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;态</button>
			</div>
			<select class="form-control"   name="sfzt">
				<option value="Y">暂停</option>
				<option value="N">正常</option>
			</select>
		</div>
		<div class="input-group" style="padding: 0px 20px 8px 20px;">
			<div class="input-group-btn">
				<button style="margin-right:-2px;height:34px"  type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown"> 到期日期</button>
			</div>
			<input style="max-width: 270px;" type="text" class="form-control layer-date" placeholder="请选择日期" onclick="laydate({istime: true, format: 'YYYY-MM-DD'})" name="op_rq">
		</div>
		<div class="input-group" style="padding: 0px 20px 10px 20px;">
			<div class="input-group-btn">
				<button style="margin-right:-2px;height:34px"  type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown">备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注</button>
			</div>
			<input type="text" class="form-control " name="yz">
		</div>
		<div style="position: absolute;width:100%;bottom:0px;padding: 0px 20px 10px 20px;">
			<button type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown"
					style="background-color: #e2e2e2;" onclick="layer.closeAll()">返回
			</button>
			<button type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown"
					style="background-color: #f54141;color: white;float: right" id="save_do">保存
			</button>
		</div>
	</form>
</div>

<!--页面加载缓冲图标-->
<div id='loadingDiv' style="position:absolute;z-index:1000;top:0px; left:0px;
	width:100%;height:100%;background:white;text-align: center;">
	<h1 style="top: 30%; position: relative;">
		<img src="../../rs/img/loading-2.gif" /><br>
	</h1>
</div>
<script>

	/*页面加载缓冲*/
	function closeLoading() {
		$("#loadingDiv").fadeOut("normal", function () {
			$(this).remove();
		});
	}
	var no;
	$.parser.onComplete = function () {
		if (no) clearTimeout(no);
		no = setTimeout(closeLoading, 1000);
	}
	var sign = URLencode($.cookie('sign'));
	$(function(){
		if(sign==="undefined"){
			window.location.href = "login.html";
		}
		f_sheard();
		sel_cobh();
		var getdata;
	});
	//判断用户权限&加载数据
	function f_sheard(){
		$.ajax({
			type: "post",
			url:G_url+'syjm/see?sign='+sign,
			data: 'sign=' + sign,
			dataType: "json",
			success: function (usedata){
				getdata=usedata;
				if (usedata.ok) {
					$('#table').datagrid({
						data: usedata.data
					});
				}else{
					window.location.href = 'login.html';
				}
			},
			error: function (XMLHttpRequest, textStatus, errorThrown) {
			}
		});
	}
	$("#save_do").on("click",function(){
		var rid=$("input[name='rid']").val();
		var cobh=$("input[name='cobh']").val();
		var jmg=$("input[name='jmg']").val();
		var bz=$("input[name='bz']").val();
		var sfzt=$("select[name='sfzt']").val();
		var op_rq=$("input[name='op_rq']").val();
		var yz=$("input[name='yz']").val();
			$.ajax({
				type: "post",
				url:G_url+'syjm/edit?sign='+sign,
				data:"rid="+rid+"&cobh="+cobh+"&jmg="+jmg+"&bz="+bz+"&op_rq="+op_rq+"&sfzt="+sfzt+"&yz="+yz,
				dataType: "json",
				success: function (result){
					if (result.ok){
						$('#table').datagrid('updateRow',{
							index: rowindex,
							row: {
								jmg: jmg,
								bz: bz,
								sfzt: sfzt,
								op_rq: op_rq,
								yz: yz
							}
						});
						layer.msg(result.msg);
					} else {
						layer.msg(result.msg);
					}
				},
				error: function (XMLHttpRequest, textStatus, errorThrown) {
				}
			});

			layer.closeAll();

	});





	$('#searchtext').bind('keypress',function(event){
		if(event.keyCode == "13") {
			do_search();
		}
	});

	function do_search(){
		var gjc=$('#searchtext').val(); //搜索关键词
		if(gjc==""){
			console.log(getdata);
			$('#table').datagrid({
				data: getdata.data
			});

		}else{
			var newdata=[];
			for(var i=0;i<getdata.data.length;i++){
				str=transform(getdata.data[i]).join(',');
				row=str.indexOf(gjc);
				if(row>=0){
					newdata.push(getdata.data[i]);
				}
			}

			$('#table').datagrid({
				data: newdata
			});
		}
	}
	function transform(obj){
		var arr = [];
		for(var item in obj){
			arr.push(obj[item]);
		}
		return arr;
	}


		var rowindex;
		function open_edit(r){
			var rowdata=$('#table').datagrid('getData');
			var row=rowdata.rows[r];
			rowindex=r;
			if (row){
				$("#open_edit").show();
				$('#edit_from').form('load',row);
				layer.open({
					title: "修改",
					type: 1,
					offset: '100px',//top顶部偏移
					skin: 'layui-layer-rim', //加上边框
					area: ['400px', '400px'], //宽高
					shadeClose: true,
					content: $('#edit_from')
				});
			}
		}

		function formatId(value,rowData,rowIndex){
			return "<a href='javascript:void(0)' onclick='open_edit("+rowIndex+");'>"+value+"</a>";
		}
		function formatzt(value,rowData,rowIndex){
			if(value=="Y"){
				return "<span style='color:red;'>暂停</span>";
			}else{
				return "<span style='color:blue;'>正常</span>";
			}
		}

	function sel_cobh(){
		$.ajax({
			type: "post",
			url:G_url+'doi_bh/see/sycp',
			data:'sign='+sign,
			dataType: "json",
			success: function (result){
				var ff = result.data;
				var html = '';
				$.each(ff, function (a, b) {//直接取出json的prolist做each循环.
					html += "<option value='"+b.bh+"'>" + b.mc + "</option>";//拼接字符串.
				});
				$("#cobh").append(html);
			},
			error: function (XMLHttpRequest, textStatus, errorThrown) {
			}
		});
	}



	$('#cobh').change(function(){
		var cobh=$(this).children('option:selected').val();//这就是selected的值
		$.ajax({
			type: "post",
			url:G_url+'syjm/see?sign='+sign,
			data:'cobh='+cobh,
			dataType: "json",
			success: function (result){
				if (result.ok){
					getdata=result;
					$('#table').datagrid({
						data: result.data
					});
				} else {
					layer.msg(result.msg);
				}
			},
			error: function (XMLHttpRequest, textStatus, errorThrown) {
			}
		});


	})

</script>
<script src="../../rs/plugins/layer/layer.min.js"></script>
<script src="../../rs/plugins/laydate/laydate.js"></script>
<script src="../../rs/js/bootstrap.js"></script>
<script src="../../rs/plugins/md5.js"></script>
</body>
</html>